﻿#region [ License information          ]
/* ************************************************************
 *
 * Copyright (c) Bjørn Bouet Smith, 2012
 *
 * This source code is subject to terms and conditions of 
 * Microsoft Public License (Ms-PL).
 * 
 * A copy of the license can be found in the license.txt
 * file at the root of this distribution. If you can not 
 * locate the License, please send an email to bjornsmith@gmail.com
 * 
 * By using this source code in any fashion, you are 
 * agreeing to be bound by the terms of the Microsoft 
 * Public License.
 *
 * You must not remove this notice, or any other, from this
 * software.
 *
 * ************************************************************/
#endregion

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Smith.BuildExtensions.ConfigurationTransformation;

namespace BuildExtensionsTests
{
    [TestClass]
    public class ConfigTransformationEngineTest
    {
        [TestMethod]
        public void ShouldCallTransformOnTransformer()
        {
            Mock<IConfigTransformer> transformer = new Mock<IConfigTransformer>();
            Mock<IConfigWriter> writer = new Mock<IConfigWriter>();

            ConfigTransformationEngine engine = new ConfigTransformationEngine(transformer.Object, writer.Object);

            engine.DoTransformation();

            transformer.Verify(t => t.TransformConfiguration(), Times.Once());
        }

        [TestMethod]
        public void ShouldCallWriterWithOutputFromTransformer()
        {
            Mock<IConfigTransformer> transformer = new Mock<IConfigTransformer>();
            Mock<IConfigWriter> writer = new Mock<IConfigWriter>();

            const string TransformedConfig = "transformed config";
            transformer.Setup(t => t.TransformConfiguration()).Returns(TransformedConfig);

            ConfigTransformationEngine engine = new ConfigTransformationEngine(transformer.Object, writer.Object);

            engine.DoTransformation();

            writer.Verify(w => w.WriteConfiguration(It.Is<string>(s => s.Equals(TransformedConfig))), Times.Once());
        }

    }
}
